package org.utils.mail;

import java.util.ArrayList;
import java.util.Properties;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

/**
 * @author Mektoub
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class MailInfo
{
	public static final String SMTP_HOST_PROPERTY = "mail.smtp.host";
	public static final String HTML_CONTENT = "text/html";
	public static final String PLAIN_TEXT_CONTENT = "test/plain";

	private InternetAddress from = null;
	private ArrayList to = new ArrayList();
	private ArrayList cc = new ArrayList();
	private ArrayList bcc = new ArrayList();
	private ArrayList replyto = new ArrayList();
	
	private String subject = "No subject";
	private String message = "";
	private String contentType = "text/plain";
	
	private ArrayList attachements = new ArrayList();
	
	private Properties props = new Properties();
	/**
	 * Constructor for MailInfo.
	 */
	public MailInfo()
	{
		super();
	}
	/**
	 * Returns the from.
	 * @return InternetAddress
	 */
	public InternetAddress getFrom()
	{
		return from;
	}
	/**
	 * Returns the to.
	 * @return ArrayList
	 */
	public InternetAddress[] getTo()
	{
		InternetAddress[] addresses = new InternetAddress[to.size()];
		return (InternetAddress[]) to.toArray(addresses);
	}
	/**
	 * Returns the to.
	 * @return ArrayList
	 */
	public InternetAddress[] getReplyTo()
	{
		InternetAddress[] addresses = new InternetAddress[replyto.size()];
		return (InternetAddress[]) replyto.toArray(addresses);
	}
	/**
	 * Returns the cc.
	 * @return ArrayList
	 */
	public InternetAddress[] getCc()
	{
		InternetAddress[] addresses = new InternetAddress[cc.size()];
		return (InternetAddress[]) cc.toArray(addresses);
	}
	/**
	 * Returns the cc.
	 * @return ArrayList
	 */
	public InternetAddress[] getBcc()
	{
		InternetAddress[] addresses = new InternetAddress[bcc.size()];
		return (InternetAddress[]) bcc.toArray(addresses);
	}
	/**
	 * Returns the subject.
	 * @return String
	 */
	public String getSubject()
	{
		return subject;
	}
	/**
	 * Returns the message.
	 * @return String
	 */
	public String getMessage()
	{
		return message;
	}
	/**
	 * Returns the contentType.
	 * @return String
	 */
	public String getContentType()
	{
		return contentType;
	}
	/**
	 * Returns the props.
	 * @return Properties
	 */
	public Properties getProperties()
	{
		return props;
	}
	/**
	 * Sets the from.
	 * @param pFrom The from to set
	 */
	public void setFrom(String pFrom) throws AddressException
	{
		this.from = new InternetAddress(pFrom);
	}
	/**
	 * Sets the from.
	 * @param pFrom The from to set
	 */
	public void setFrom(InternetAddress pFrom)
	{
		this.from = pFrom;
	}
	/**
	 * Sets the to.
	 * @param to The to to set
	 */
	public void addTo(String address) throws AddressException
	{
		to.add(new InternetAddress(address));
	}
	/**
	 * Sets the to.
	 * @param to The to to set
	 */
	public void addTo(InternetAddress address)
	{
		to.add(address);
	}
	/**
	 * Sets the to.
	 * @param to The to to set
	 */
	public void addReplyTo(String address) throws AddressException
	{
		replyto.add(new InternetAddress(address));
	}
	/**
	 * Sets the to.
	 * @param to The to to set
	 */
	public void addReplyTo(InternetAddress address)
	{
		replyto.add(address);
	}
	/**
	 * Sets the cc.
	 * @param cc The cc to set
	 */
	public void addCc(String address) throws AddressException
	{
		cc.add(new InternetAddress(address));
	}
	/**
	 * Sets the cc.
	 * @param cc The cc to set
	 */
	public void addCc(InternetAddress address)
	{
		cc.add(address);
	}
	/**
	 * Sets the bcc.
	 * @param bcc The bcc to set
	 */
	public void addBcc(String address) throws AddressException
	{
		bcc.add(new InternetAddress(address));
	}
	/**
	 * Sets the bcc.
	 * @param bcc The bcc to set
	 */
	public void addBcc(InternetAddress address)
	{
		bcc.add(address);
	}
	/**
	 * Sets the subject.
	 * @param pSubject The subject to set
	 */
	public void setSubject(String pSubject)
	{
		this.subject = pSubject;
	}
	/**
	 * Sets the message.
	 * @param pMessage The message to set
	 */
	public void setMessage(String pMessage)
	{
		this.message = pMessage;
	}
	/**
	 * Sets the contentType.
	 * @param contentType The contentType to set
	 */
	public void setContentType(String pContentType)
	{
		this.contentType = pContentType;
	}
	/**
	 * Sets the props.
	 * @param props The props to set
	 */
	public void addProperty(String name, String value)
	{
		props.setProperty(name, value);
	}
	/**
	 * Method addAttachment.
	 * @param string
	 */
	public void addAttachment(String filename)
	{
		attachements.add(filename);
	}
	/**
	 * Method addAttachment.
	 * @param string
	 */
	public ArrayList getAttachments()
	{
		return attachements;
	}
	/**
	 * Method addAttachment.
	 * @param string
	 */
	public boolean hasAttachments()
	{
		return (attachements.size() != 0);
	}
}
